package com.huawei.appmarket.service.appmgr.view.activity;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.text.format.DateUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.huawei.appmarket.service.appmgr.bean.ApkInstalledInfo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import o.azb;
import o.cnz;
import o.coa;
import o.Logger;
import o.dtg;
import o.dtm;
import o.epv;
import o.erm;
import o.ewm.c;
import o.ewm.e;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;
import o.fho;
import o.fhz;

public class EditInstalledListAdapter extends BaseAdapter {
    private static final String TAG = "EditInstalledListAdapter";
    private Context context = null;
    private View emptyView;
    private coa mPackageState;
    public List<ApkInstalledInfo> requestInstalled = new ArrayList();
    public Map<String, Long> selectPkg = new ConcurrentHashMap();
    private ColorDrawable transparentDrawable;

    static class d {
        private CheckBox ˊ;
        private dtm ˎ;
        private View ˏ;

        private d() {
            this.ˎ = new dtm();
        }

        public void ˊ(View view) {
            this.ˏ = view;
        }

        public dtm ˏ() {
            return this.ˎ;
        }

        public CheckBox ˊ() {
            return this.ˊ;
        }

        public void ˎ(CheckBox checkBox) {
            this.ˊ = checkBox;
        }
    }

    public EditInstalledListAdapter(Context context, List<ApkInstalledInfo> list, View view) {
        this.context = context;
        this.emptyView = view;
        this.transparentDrawable = new ColorDrawable(context.getResources().getColor(c.ˉ));
        this.transparentDrawable.setBounds(0, 0, 0, 0);
        setDatas(list);
        fhz ˋ = fho.ˏ().ˋ("PackageManager");
        if (ˋ != null) {
            this.mPackageState = (coa) ˋ.ॱ(coa.class);
        }
    }

    public ConcurrentHashMap<String, Long> getSelectPkg() {
        return new ConcurrentHashMap(this.selectPkg);
    }

    public void setSelectPkg(Map<String, Long> map) {
        this.selectPkg.putAll(map);
    }

    public void clearSelectPkg() {
        this.selectPkg.clear();
    }

    public void addSelectPkg(String str, long j) {
        this.selectPkg.put(str, Long.valueOf(j));
    }

    public synchronized void setDatas(List<ApkInstalledInfo> list) {
        List<ApkInstalledInfo> arrayList = new ArrayList(list);
        Collection arrayList2 = new ArrayList();
        for (ApkInstalledInfo apkInstalledInfo : arrayList) {
            cnz o_cnz = cnz.ॱ;
            if (this.mPackageState != null) {
                o_cnz = this.mPackageState.ˎ(apkInstalledInfo.ॱ());
            }
            if (o_cnz == cnz.ॱ) {
                arrayList2.add(apkInstalledInfo);
            }
        }
        this.requestInstalled.clear();
        this.requestInstalled.addAll(arrayList2);
        Collections.sort(this.requestInstalled, new dtg());
        refreshSelectPkg();
        if (this.requestInstalled.isEmpty()) {
            this.emptyView.setVisibility(0);
        } else {
            this.emptyView.setVisibility(8);
        }
    }

    private void refreshSelectPkg() {
        if (this.requestInstalled.isEmpty() || this.selectPkg.isEmpty()) {
            Logger.ˎ(TAG, "requestInstalled or selectPkg is empty");
            return;
        }
        List arrayList = new ArrayList();
        for (ApkInstalledInfo ॱ : this.requestInstalled) {
            arrayList.add(ॱ.ॱ());
        }
        Iterator it = this.selectPkg.keySet().iterator();
        while (it.hasNext()) {
            if (!arrayList.contains((String) it.next())) {
                it.remove();
            }
        }
    }

    public int getCount() {
        return this.requestInstalled.size();
    }

    public Object getItem(int i) {
        if (this.requestInstalled.isEmpty()) {
            return null;
        }
        return this.requestInstalled.get(i);
    }

    public long getItemId(int i) {
        return (long) i;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        d dVar;
        ApkInstalledInfo apkInstalledInfo = (ApkInstalledInfo) this.requestInstalled.get(i);
        if (view == null || !(view.getTag() instanceof d)) {
            view = LayoutInflater.from(this.context).inflate(h.ͺ, null);
            d dVar2 = new d();
            dVar2.ˊ(view.findViewById(j.ٴˋ));
            dVar2.ˏ().ˎ((ImageView) view.findViewById(j.ॱʳ));
            azb.ॱ(dVar2.ˏ().ˊ());
            dVar2.ˏ().ˎ((TextView) view.findViewById(j.ॱۥ));
            dVar2.ˏ().ˊ((TextView) view.findViewById(j.ॱˬ));
            dVar2.ˏ().ˋ((TextView) view.findViewById(j.ॱˇ));
            dVar2.ˎ((CheckBox) view.findViewById(j.ᶫ));
            azb.ʻ(dVar2.ˊ());
            setDividerMarginStart(view);
            view.setTag(dVar2);
            dVar = dVar2;
        } else {
            dVar = (d) view.getTag();
        }
        initViewLabel(dVar.ˏ(), apkInstalledInfo);
        if (this.selectPkg.get(apkInstalledInfo.ॱ()) != null) {
            dVar.ˊ().setChecked(true);
        } else {
            dVar.ˊ().setChecked(false);
        }
        return view;
    }

    private void setDividerMarginStart(@NonNull View view) {
        azb.ˎ(view, j.ˑ, epv.ᐝ(), azb.ˏ(this.context));
    }

    private void initViewLabel(dtm o_dtm, ApkInstalledInfo apkInstalledInfo) {
        erm.ˏ().ˎ(e.ꓸ);
        erm.ˏ().ˋ(o_dtm.ˊ(), apkInstalledInfo.ॱ());
        o_dtm.ॱ().setText(apkInstalledInfo.ˎ());
        if (apkInstalledInfo.ʽ()) {
            o_dtm.ˏ().setText(apkInstalledInfo.ˊ());
            o_dtm.ˏ().setTextColor(this.context.getResources().getColor(c.ʻ));
            o_dtm.ˏ().setCompoundDrawables(null, null, null, null);
            o_dtm.ˏ().setCompoundDrawables(this.transparentDrawable, this.transparentDrawable, this.transparentDrawable, this.transparentDrawable);
            o_dtm.ˏ().setCompoundDrawablePadding(0);
            if (dtg.ˎ(apkInstalledInfo.ʻ())) {
                o_dtm.ˋ().setVisibility(0);
                o_dtm.ˋ().setText(DateUtils.formatDateTime(this.context, apkInstalledInfo.ˋ(), 131092));
                return;
            }
            o_dtm.ˋ().setVisibility(8);
            return;
        }
        o_dtm.ˏ().setText(this.context.getString(n.ﹳˎ));
        o_dtm.ˏ().setAlpha(1.0f);
        o_dtm.ˏ().setTextColor(this.context.getResources().getColor(c.ˊˋ));
        o_dtm.ˋ().setVisibility(8);
    }
}
